Skip the tag-dictionary walk in IndexName equality when tags are identical#224
Merged
Merged
Conversation
…entical
## Summary
Adds a `===` fast path to `==` and `isequal` on `IndexName` so a comparison skips the tag-dictionary walk when both names carry the same tags object. An index leg reused across tensors carries the same `IndexName`, and therefore the same tags container, so the common equal case drops from walking the tag dictionary to a single pointer check (roughly 6.5 ns to 2.7 ns for a two-tag name).
The check sits on the tags field, which is the only costly one to compare: `uuid` and `plev` stay as the cheap primary discriminators, so names with a different id or prime level short-circuit before reaching the tags at all. This is sound because the tags are `SortedDict{Symbol, Symbol}` and `Symbol` equality is reflexive, so identical tag objects always compare equal.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #224 +/- ##
=======================================
Coverage 76.90% 76.90%
=======================================
Files 29 29
Lines 1706 1706
=======================================
Hits 1312 1312
Misses 394 394
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mtfishman
enabled auto-merge (squash)
July 20, 2026 21:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
===fast path to==andisequalonIndexNameso a comparison skips the tag-dictionary walk when both names carry the same tags object. An index leg reused across tensors carries the sameIndexName, and therefore the same tags container, so the common equal case drops from walking the tag dictionary to a single pointer check.The check sits on the tags field, which is the only costly one to compare:
uuidandplevstay as the cheap primary discriminators, so names with a different id or prime level short-circuit before reaching the tags at all. This is sound because the tags areSortedDict{Symbol, Symbol}andSymbolequality is reflexive, so identical tag objects always compare equal.Comparing two two-tag
IndexNames (Julia 1.12, minimum of@benchmark, zero allocations), the equal case where both names carry the same tags object drops from about 6.5 ns to 2.7 ns. The other paths are unchanged: names with a different id short-circuit on theuuidcomparison at about 3 ns, and names with different tags fall through to the full dictionary walk at about 6 ns.